﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using MockupDesigner.Items;
using System.Windows.Input;
using MockupDesigner.AppItems;

namespace MockupDesigner.Editors.TextEditors
{
    public class SimpleTextEditor : TextEditorBase
    {
        private ITextItem itemToEdit;

        public bool IsMultiLine { get; set; }

        public override void element_LostFocus(object sender, RoutedEventArgs e)
        {
            this.itemToEdit.Text = base.element.Text;
            LeaveFocus();
        }

        public override void element_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (!this.itemToEdit.Multiline && e.Key == Key.Enter)
            {
                element_LostFocus(sender, e);
            }
        }

        public override void SetItem(ItemBase itemToEdit)
        {
            base.SetItem(itemToEdit);
            this.itemToEdit = itemToEdit as ITextItem;
            base.element.Text = this.itemToEdit.Text;
            base.element.AcceptsReturn = this.itemToEdit.Multiline;
        }

    }
}
